<!doctype html>
<html class="no-js"
      xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="/admin/layout :: head">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，暂不支持。 请 <a href="http://browsehappy.com/"
                                                               target="_blank">升级浏览器</a>
    以获得更好的体验！</p>
<![endif]-->

<th:block th:replace="/admin/layout :: nav_main"></th:block>

<div class="am-cf admin-main">
    <!-- sidebar start -->
    <th:block th:replace="/admin/layout :: sidebar('home')"></th:block>
    <!-- sidebar end -->

    <!-- content start -->
    <div class="admin-content">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">首页</strong> /
                <small>公告管理</small>
            </div>
        </div>

        <div class="am-g">
            <div class="am-u-sm-12">
                <div class="am-padding-bottom-lg">
                    <a shiro:hasRole="ADMIN" href="/admin/notice/new" class="am-btn am-btn-secondary am-round">添加公告</a>
                </div>
                <a class="am-btn am-btn-default" href="/admin/account"
                   th:href="@{'/admin/notice/list'}">全部</a>

                <table class="am-table am-table-bd am-table-striped admin-content-table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>标题</th>
                        <th>发布日期</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="u,iterStat : ${pagination}">
                        <td th:utext="${u.id}"></td>
                        <td th:utext="${u.title}"></td>
                        <td th:text="${#calendars.format(u.createTime, 'yyyy-MM-dd')}">
                        </td>                        <td>
                            <div class="am-dropdown" data-am-dropdown="">
                                <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle"
                                        data-am-dropdown-toggle=""><span class="am-icon-cog"></span>
                                    <span class="am-icon-caret-down"></span></button>
                                <ul class="am-dropdown-content">
                                    <li shiro:hasRole="ADMIN"><a href="#"
                                                                 th:href="@{'/admin/notice/edit/'+${u.id}}">修改</a>
                                    </li>
                                    <li shiro:hasRole="ADMIN"><a href="#"
                                                                   th:href="@{'/admin/notice/show/'+${u.id}}">查看</a>
                                    </li>

                                    <li shiro:hasRole="NORMARL"><a href="#"
                                                                   th:href="@{'/admin/notice/show/'+${u.id}}">查看</a>
                                    </li>
                                    <li shiro:hasRole="ADMIN"><a href="#"
                                                                 th:href="@{'/admin/notice/delete/'+${u.id}}"
                                                                 class="delete">删除</a></li>

                                </ul>
                            </div>
                        </td>
                    </tr>

                    </tbody>
                </table>

                <ul class="am-pagination">
                    <li th:each="pageable,iterStat: ${#numbers.sequence(1,pagination.totalPages==0?1:pagination.totalPages)}" class="am-pagination">
                    <a href=""
                           th:href="@{'/admin/notice/list?page=' + ${iterStat.count}}"
                           th:text="${iterStat.count}"></a>
                    </li>
                </ul>

            </div>
        </div>

    </div>
    <!-- content end -->

</div>

<a href="#" class="am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}">
    <span class="am-icon-btn am-icon-th-list"></span>
</a>

<div class="am-modal am-modal-confirm" tabindex="-2" id="my-confirm2">
    <div class="am-modal-dialog">
        <div class="am-modal-bd">
            确定要删除这条数据吗？
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-cancel="">取消</span>
            <span class="am-modal-btn" data-am-modal-confirm="">确定</span>
        </div>
    </div>
</div>

<th:block th:replace="/admin/layout :: footer"></th:block>

<script type="text/javascript">
    $(function () {
        $('.delete').on('click', function () {
            var href = $(this).attr('href');
            $('#my-confirm2').modal({
                relatedTarget: this,
                onConfirm: function (options) {
                    $.ajax({
                        url: href,
                        dataType: 'json',
                        type: 'post',
                        success: function (json) {
                            if (json.success) {
                                location.reload();
                            }
                        }
                    });
                },
                onCancel: function () {

                }
            });
            return false;
        });
    })
</script>
</body>
</html>
